package com.jml.api.controller;

//import com.codingapi.tx.annotation.TxTransaction;
import com.jml.api.dao分布式事务.OrderEntity;
import com.jml.api.dao分布式事务.OrderMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Api("消费者-订单服务")
public class OrderController {

	//RestTemplate默认整合了ribbon，和httpclient
	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private OrderMapper orderMapper;

	@RequestMapping("/getorder")
	public String getOrder() {
		String memberUrl = "http://provider/getMember";
		String result = restTemplate.getForObject(memberUrl, String.class);
		System.out.println("会员服务调用订单服务,result:" + result);
		return result;
	}

	@ApiOperation("获取订单相关的信息")
	@ApiImplicitParam(name = "orderName",value = "order信息",required = true,dataType = "String")
	@PostMapping("/getOrderSwagger")
	public String getOrderSwagger(String orderName){
		return "orderName:"+orderName;
	}


//true表示发起方，false表示参与方默认是false
/*	@TxTransaction(isStart = true)
	@Transactional
	@RequestMapping("/tx")
	public String txTransaction() {
		String memberUrl = "http://provider/txTransaction";
		String result = restTemplate.getForObject(memberUrl, String.class);
		System.out.println("会员服务调用订单服务,result:" + result);

		OrderEntity orderEntity = new OrderEntity();
		orderEntity.setName("会员充值");
		orderEntity.setOrderCreatetime(new Date());
		// 价格是300元
		orderEntity.setOrderMoney(300d);
		// 状态为 未支付
		orderEntity.setOrderState(0);
		Long commodityId = 3L;
		// 商品id
		orderEntity.setCommodityId(commodityId);
		// ##################################################
		// 1.先下单，创建订单 (往订单数据库中插入一条数据)
		int orderResult = orderMapper.addOrder(orderEntity);
		return result;
	}*/
}


